package initdata

import (
	"local.public/innerpkg/dbtool"
	"local.public/innerpkg/logger"
)

/*
   说明：初始化基础数据
*/

// 基础数据
var (
	// 密码：123456
	password = "$2a$10$CrHfdigkqfsh94kDgHc7SOKUa3dLM6VHvHDuq0EAH8rq0ybjMbpbK"
)

//// 角色数据
//var subtypes = []models.MaterialSubType{
//	{
//		InnerId:         1,
//		Kind:            "sys",
//		Category:        "5",
//		MaterialType:    "music",
//		MaterialSubtype: "pop2_music",
//		NameZh:          "流行音乐",
//	},
//	{
//		InnerId:         2,
//		Kind:            "sys",
//		Category:        "5",
//		MaterialType:    "music",
//		MaterialSubtype: "pop_music",
//		NameZh:          "流行音乐1",
//	},
//}

//// 创建角色
//func InitMaterialSubType() {
//	db := datastore.GetDB()
//	for _, subtype := range subtypes {
//		db.Save(&subtype)
//	}
//}

// 初始化数据
func BusinessTableAutoMigrate() {
	db := dbtool.GetBusinessDB()
	if db != nil {
		//db.AutoMigrate(&models.AiModelVersion2Node{})
		//db.AutoMigrate(&models.AiModelVersion{})
		//db.AutoMigrate(&models.Model3d{})
		//
		//db.AutoMigrate(&models.Point{})
		//db.AutoMigrate(&models.Label{})
		//
		//db.AutoMigrate(&models.AiSample{})
		//db.AutoMigrate(&models.AiSample2Label{})
		//db.AutoMigrate(&models.AlarmRecord{})
		//db.AutoMigrate(&models.Station{})
		//db.AutoMigrate(&models.StationDevice{})
		//db.AutoMigrate(&models.SensorDataRecord{})
		////db.AutoMigrate(&models.AiTaskResult{}, &models.AiSubtaskResult{})
		//
		//{
		//	var sViewSql string
		//	sViewSql = "create or replace view " + (&models.AiModelVersion2NodeShow{}).TableName() +
		//		" as select " +
		//		"v2n.*, ver.model_name, ver.dataset, ver.param_filename, ver.weights_filename, ver.voc_filename, ver.version " +
		//		" from " + (&models.AiModelVersion2Node{}).TableName() + " v2n " +
		//		" left outer join  " + (&models.AiModelVersion{}).TableName() + " ver on ver.id =  v2n.version_dbid "
		//	db.Exec(sViewSql)
		//}
		//
		//{
		//	var sViewSql string
		//	sViewSql = "create or replace view " + (&models.StationDeviceShow{}).TableName() +
		//		" as select " +
		//		"dev.*, sta.edge_code, sta.edge_name, sta.point_id, sta.mqtt_clientid " +
		//		" from " + (&models.StationDevice{}).TableName() + " dev " +
		//		" left outer join  " + (&models.Station{}).TableName() + " sta on sta.id =  dev.station_id "
		//	db.Exec(sViewSql)
		//}

		logger.Info("TableAutoMigrate 完成")
	}
}

// 初始化数据
func LogsTableAutoMigrate() {
	db := dbtool.GetLogsDB()
	if db != nil {
		//db.AutoMigrate(&models.AiModelVersion2Node{})
		//db.AutoMigrate(&models.AiModelVersion{})
		//db.AutoMigrate(&models.Model3d{})
		//
		//db.AutoMigrate(&models.Point{})

		logger.Info("TableAutoMigrate 完成")
	}
}

// 初始化数据
func InitData() {
	BusinessTableAutoMigrate()
	LogsTableAutoMigrate()
	logger.Info("数据库初始化完成")
}
